/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socof.wget;

import htmlparser.UrlParser;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 *
 * @author Carlos
 */
public class WebResource 
{   
    //private int id;
    private URL sourceUrl;
    private String localPath;
    //private WebResourceType type;
    /*private String domain;
    private String filename;
    private String localPath;
    private FileStatus status;    
    private String type;*/
    //private int level;
    //private Date lastUpdated;
    
    public WebResource (String url, String localPath) throws MalformedURLException
    {
        this.sourceUrl = new URL(url);
        this.localPath = localPath;
    }    
    
    public static WebResource getNextToDownload()
    {
        // go to db and get next item to be downloaded
        return PendingQueue.getInstance().poll();
    }
    
    public static WebResource getNextToParse()
    {
        // go to db and get next item to be parsed
        return ToParseQueue.getInstance().poll();
    }
    
    public void addToPendingQueue ()
    {
        // saves file to db with status pending
        //this.status = FileStatus.PENDING;
        PendingQueue.getInstance().offer(this);
    }
    
    public void addToParsingQueue ()
    {
        // saves file to db with status pending
        //this.status = FileStatus.TO_PARSE;
        ToParseQueue.getInstance().offer(this);
    }
    
    public boolean download ()
    {
        
        // Download the file using URL to correct location
        
        // if (html) this.setStatusToParse();
        // else this.setStatusComplete();
        
        return true;
    }
    
    public boolean parse ()
    {
        UrlParser parser = new UrlParser();
        List<String> result = parser.getUrl(this, "all");
        for (String r : result)
        {
            
        }
        return true;
    }

    /**
     * @return the sourceUrl
     */
    public URL getSourceUrl()
    {
        return sourceUrl;
    }

    /**
     * @return the localPath
     */
    public String getLocalPath()
    {
        return localPath;
    }

    /**
     * @param localPath the localPath to set
     */
    public void setLocalPath(String localPath)
    {
        this.localPath = localPath;
    }
    
    /*public void setType()
    {
    }
    
    public enum WebResourceType
    {
        HTML,
        OTHER
    }*/
}
